/**
 * 获取购物车的异步操作
 * 异步操作的函数中有两个参数
 * 参数1为dispatch
 * 参数2为getState
 * 注意：如果你在项目中集成了redux-thunk，那么这个redux-thunk就将异步方法，转成actionCreator
 */
import axios from "axios"
import {getShopcartCreator} from '@/store/action/shopcartAction'
export const getShopcartDataAsync=async(dispatch,getState)=>{
   console.log('-----------getShopcartDataAsync-------------');
   const result=await axios.get("http://www.zhaijizhe.cn:3003/shopcart/getShopcartData")
   console.log('result',result.data.data);
   dispatch(getShopcartCreator(result.data.data))
}

export const changeNumAsync=(payload)=>{
    return async(dispatch,getState)=>{
        console.log('---------changeNumAsync类似与action的功能--------------');
        const result=await axios.post('http://www.zhaijizhe.cn:3003/shopcart/changeNum',payload)
        if(result.data.code){
            dispatch(getShopcartDataAsync)
        }
    }
}